cmake_minimum_required(VERSION 3.5)
project(yolo_detect_pkg)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Ofast -DNDEBUG -Wno-deprecated-declarations")

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()
find_package(glog REQUIRED)
find_package(OpenCV 4.2 REQUIRED)
# 使用正确版本的CUDA


# tensorrt
set(TENSORRT_INCLUDE_DIRS /usr/include/aarch64-linux-gnu/)   # 头文件夹
set(TENSORRT_LIBS /usr/lib/aarch64-linux-gnu/libnvinfer.so /usr/lib/aarch64-linux-gnu/libnvonnxparser.so)  # 依赖动态库


# cuda
set(CUDA_ROOT_PATH /usr/local/cuda-11.4/) # 根目录
set(CUDA_INCLUDE_DIRS ${CUDA_ROOT_PATH}/include/)   # 头文件夹
set(CUDA_LIBS ${CUDA_ROOT_PATH}lib64/libcudart.so)  # 依赖动态库


# Default to C++14
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()
include_directories(
  include
  include/yolo_detect_pkg
  ${TENSORRT_INCLUDE_DIRS}
  ${CUDA_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)
# message(ERROR ,"${OpenCV_INCLUDE_DIRS}")



# find dependencies
find_package(ament_cmake REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(yolo_detect_message REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(image_transport REQUIRED)
find_package(client_interfaces REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_sensor_msgs REQUIRED)
find_package(tf2 REQUIRED)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

add_library(YOLO_DETECT 
  src/yolo_detect_pkg/yolov10.cpp
  src/yolo_detect_pkg/yolo_detect.cpp
)
target_link_libraries(YOLO_DETECT ${OpenCV_LIBS} ${TENSORRT_LIBS} ${CUDA_LIBS} ${glog_LIB})
ament_target_dependencies(YOLO_DETECT
  cv_bridge
  yolo_detect_message
  rclcpp
  sensor_msgs
  std_msgs
  geometry_msgs
  image_transport
  client_interfaces
  tf2 
  tf2_sensor_msgs  
  tf2_ros 
)

add_executable(yolo_detect_pkg_node
  src/yolo_detect_pkg_node.cpp)
target_link_libraries(yolo_detect_pkg_node
YOLO_DETECT)
ament_target_dependencies(yolo_detect_pkg_node 
  cv_bridge
  yolo_detect_message
  rclcpp
  client_interfaces
  sensor_msgs
  std_msgs
  geometry_msgs
  tf2 
  tf2_sensor_msgs  
  tf2_ros 
  image_transport
)

install(TARGETS yolo_detect_pkg_node
  DESTINATION lib/${PROJECT_NAME})

install(TARGETS YOLO_DETECT
  ARCHIVE
  DESTINATION lib
  LIBRARY
  DESTINATION lib)



install(DIRECTORY launch config source DESTINATION share/${PROJECT_NAME})
ament_package()
